﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

using YT.DB;
using YT.Commons;
using YT.Modules;

namespace YT.XH.IgE
{
    public partial class frmIgETreatHistory : Form
    {
        private DBAccess mdbcon = new DBAccess(false, false);
        private string mstrRecID = string.Empty;
        private string mstrSickRecID = string.Empty;
        private string mstrTableName = string.Empty;
        private FormStatus mFormStatus = new FormStatus();
        private ArrayList mArrayControl = new ArrayList();

        public frmIgETreatHistory()
        {
            InitializeComponent();
        }


        private void initControl()
        {
            this.Text = "患者诊疗记录维护";
            mstrTableName = "IgETreatHistory";
            mstrSickRecID = SysVar.SickRecID;
        }

        private void FillBaseInfo()
        {
            string strSQL = string.Empty;
            strSQL = "select * from mSickPerson where sickRecID='" + mstrSickRecID + "'";
            DataRow drRow = mdbcon.GetDataFirstRow(strSQL);
            if (drRow != null)
            {
                txtSickName.Text = CvtFunc.ToString(drRow["SickName"]);
                txtAddress.Text = CvtFunc.ToString(drRow["Address"]);
                txtPhone.Text = CvtFunc.ToString(drRow["Phone"]) + CvtFunc.ToString(drRow["MobilePhone"]);
                txtRemark.Text = CvtFunc.ToString(drRow["Remark"]);
            }

        }

        private void FillGrid()
        {
            this.dgvDetail.Rows.Clear();
            string strSQL = string.Empty;
            strSQL = "select * from " + mstrTableName + " where SickRecID='" + SysVar.SickRecID + "' order by seqno ";
            DataTable dtDtl = mdbcon.GetDataTable(strSQL);
            foreach (DataRow drRow in dtDtl.Rows)
            {
                this.dgvDetail.Rows.Add();
                this.dgvDetail.Rows[this.dgvDetail.Rows.Count - 1].Cells[ColRecID.Index].Value = CvtFunc.ToString(drRow["RecID"]);
                this.dgvDetail.Rows[this.dgvDetail.Rows.Count - 1].Cells[ColSeqNo.Index].Value = CvtFunc.ToString(drRow["SeqNo"]);
                this.dgvDetail.Rows[this.dgvDetail.Rows.Count - 1].Cells[ColCheckDate.Index].Value = BaseFunctions.FormatDate(drRow["ExamDate"].ToString(), DateFormatOption.DateFmtYMD);
                this.dgvDetail.Rows[this.dgvDetail.Rows.Count - 1].Cells[ColRemark.Index].Value = CvtFunc.ToString(drRow["Remark"]);
            }
            this.dgvDetail.EndEdit();
        }

        private void dgvDetail_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == ColDtl.Index)
            {
                string strSeqNo = string.Empty;
                if (this.dgvDetail.Rows.Count >= 1)
                {
                    strSeqNo = CvtFunc.ToString(this.dgvDetail.Rows[e.RowIndex].Cells[ColSeqNo.Index].Value);
                }
                ShowMtn(strSeqNo);
            }
        }

        private void ShowMtn(string strSeqNo)
        {
            
           
            frmIgETreatHistoryDetail frmDetail = new frmIgETreatHistoryDetail(strSeqNo, mstrSickRecID);
            frmDetail.StartPosition = FormStartPosition.CenterParent;
            frmDetail.ShowDialog();
            FillGrid();
        }

        private void frmIgETreatHistory_Load(object sender, EventArgs e)
        {
            initControl();
            FillBaseInfo();
            FillGrid();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            ShowMtn("-1");
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }

        private void btnTreatRpt_Click(object sender, EventArgs e)
        {
            using (DBAccess dbcon = new DBAccess(false, false))
            {
                PrintRpt(dbcon, mstrSickRecID); 
            }
        }

        private void PrintRpt(DBAccess dbcon, string strSickRecID)
        {
            PrintDgnosisDAL rptDAL = new PrintDgnosisDAL();
            if (rptDAL.printDgnosisDAL(dbcon, strSickRecID))
            {
                PrintInfo printInfo = new PrintInfo();
                Reports.Report rpt = new Reports.Report();
                printInfo.ReportPageTitle = SysVar.HospitalName +"\r\n" + "  屋尘螨IgG4检测报告 ";
                rpt.OeDailyCashSalesPaymentReport(dbcon, printInfo);
            }
            return;
        }

    }
}
